package ged.customizationCode.shapes;

import ged.Node;
import ged.customizationCode.functions.CustomizationCodeNodeEditPart;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.ScalablePolygonShape;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;

public class PolygonNodeFigure extends ScalablePolygonShape {

	Node node;
	private WrappingLabel fFigureNodeLabelFigure;
	CustomizationCodeNodeEditPart customizationCodeNodeEditPart = new CustomizationCodeNodeEditPart();
	IMapMode mapMode;
	
	//constructor
	public PolygonNodeFigure(Node node, IMapMode mapMode) {
		this.node = node;
		this.mapMode = mapMode;
		
		this.addPoint(new Point(mapMode.DPtoLP(0), mapMode.DPtoLP(0)));
		this.addPoint(new Point(mapMode.DPtoLP(0), mapMode.DPtoLP(40)));
		this.addPoint(new Point(mapMode.DPtoLP(40), mapMode.DPtoLP(0)));
		this.containsPoint(10, 10);
		this.shapeContainsPoint(10, 10);
		
		ged.BorderInnerMargin b_InnerMargin = node.getInnerMargin();
		//sets the margin inside the node. 
		//default code
		if (b_InnerMargin == null) {
			this.setBorder(new MarginBorder(mapMode.DPtoLP(5),
					mapMode.DPtoLP(5), mapMode.DPtoLP(5),
					mapMode.DPtoLP(5)));
		} else {
			//new code ----
			this.setBorder(new MarginBorder(mapMode.DPtoLP(
					b_InnerMargin.getInner_margin_top()), mapMode
					.DPtoLP(b_InnerMargin.getInner_margin_left()),
					mapMode.DPtoLP(
							b_InnerMargin.getInner_margin_bottom()),
							mapMode.DPtoLP(
							b_InnerMargin.getInner_margin_right())));
		}

		createContents();
	}

	private void createContents() {
		fFigureNodeLabelFigure = new WrappingLabel();
		fFigureNodeLabelFigure.setText("Node");

		this.add(fFigureNodeLabelFigure);
	}

	public WrappingLabel getFigureNodeLabelFigure() {
		return fFigureNodeLabelFigure;
	}

	//Overrides the fillShape method. There is such a method in the Rounded rectangle class
	//add gradient. fillXXX for fill colour and drawXXX for the outline of the shape
	protected void fillShape(Graphics graphics) {

		ged.Gradient fontName = node.getGradient();
		switch (fontName) {
		case VERTICAL:
			//value = "vertical";
			graphics.fillGradient(getBounds(), true);
			break;
		case HORIZONTAL:
			//value = "horizontal";
			graphics.fillGradient(getBounds(), false);
			break;
		default:
			super.fillShape(graphics);//calls the default fillShape method from the RoundedRectangle class
		}

		//-------------------------------PROBLEM---------------------------------------
		//graphics.fillRoundRectangle(getBounds(), corner.width, corner.height);
		//fillGradient method uses the foreground and background colours to set the gradient.
		//getBounds method is in the figure class and returns the bounds for a rectangle not the actual shape
		//thus, the node with the gradient seems to be like a rectangle

	}
}
